home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
6_6.lha
/
6_6
/
6_6substr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
765b
|
36 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ substr = str(3, 5)
ifdef NOTDEF // DELETE
include <str.h>
else // DELETE
include "6_6.h" // DELETE
endif // DELETE
ubstring string::operator()(int index, int count)
char *s1 = str();
int s1len = strlen(s1);
// convert left index, if necessary
if (index < 0)
index += s1len;
// left index past end of string
else if (index >= s1len)
{
substring sst(s1 + s1len, 0, this);
return sst;
}
// convert count, if necessary
int numleft = s1len - index;
if (count > numleft || count < 0)
count = numleft;
// copy the substring
substring sst(s1 + index, count, this);
return sst;